tinymce.PluginManager.add('insertFillBlank', function (editor, url) {
    var inputValue = '';
    //插件中文提示
    const pluginName = '填空';
    //插入点击执行函数
    const insertFillBlankAct = () => {
        var inputId = 'customInput_' + new Date().getTime(); // 为每个插入的输入框生成一个唯一的id
        var inputHtml =
            '<input type="text"  class="fill-blank-answer" value="' +
            inputValue +
            '" id="' +
            inputId +
            '" placeholder="请输入内容"></input>';
        editor.insertContent(inputHtml);
        editor.dom.get(inputId).focus();
        editor.dom.get(inputId).addEventListener('keyup', function () {
            let htmlElement = editor.dom.get(inputId);
            htmlElement.setAttribute('value', htmlElement.value);
            htmlElement.setAttribute('fillBlankAnswer', htmlElement.value);
        });
    };

    //设置操作图标
    editor.ui.registry.getAll().icons.insertFillBlank ||
        editor.ui.registry.addIcon(
            'insertFillBlank',
            '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1715156903220" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3015" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="20"><path d="M871.319398 88.086022C906.994237 88.086022 935.913978 117.005763 935.913978 152.680602v718.638796c0 35.674839-28.919742 64.594581-64.59458 64.59458H152.680602C117.005763 935.913978 88.086022 906.994237 88.086022 871.319398V152.680602C88.086022 117.005763 117.005763 88.086022 152.680602 88.086022h718.638796z m3.639054 66.493935H154.579957v720.378495h720.378495V154.579957z m-271.525162 138.53729v42.666667H538.783656v341.349849h64.649634v42.666667H409.484387v-42.666667h64.649635V335.783914H409.484387v-42.666667h193.948903z" fill="#2c2c2c" p-id="3016"></path></svg>',
        );
    editor.on('NodeChange', function (e) {
        if (e.element.nodeName === 'INPUT' && e.element.id.startsWith('customInput')) {
            inputValue = e.element.value;
        }
    });
    //注册按钮事件
    editor.ui.registry.addButton('insertFillBlank', {
        icon: 'insertFillBlank',
        tooltip: pluginName,
        onAction: function () {
            insertFillBlankAct();
        },
    });

    //注册执行指令
    editor.addCommand('insertFillBlank');

    return {
        getMetadata: function () {
            return {
                name: pluginName,
                url: '',
            };
        },
    };
});
